$(document).ready(function(){
	operatorLogFrame();
	closeOperatorLogFrame();
	//选择操作模块
	$('#operatorModules').combotree({    
	    url:'sys/menusTree.action?',
	    panelWidth:180,
	    valueField:'id',
	    textField:'text',
	    loadFilter: function(data){   
        	return data.rows;   
    	}
	});
	//初始化表格
	$('#dataGridTable').datagrid({
		columns:[[ 
		   {field:'workNumber',title:'工号',width:80,align:'center'},
           {field:'userName',title:'用户名',width:120,align:'center'}, 
           {field:'realName',title:'真实姓名',width:90,align:'center'},
           {field:'operatorIp',title:'操作IP',width:90,align:'center'},
           {field:'operatorModules',title:'操作模块',width:90,align:'center'},
           {field:'operatorType',title:'操作类型',width:80,align:'center',formatter:operatorTypeFormater},
           {field:'createTime',title:'操作时间',width:createTimeWidth,align:'center'}
         ]]
	});	
	
	$('#workNumber').textbox('textbox').keydown(function (e) {
		   if (e.keyCode == 13) {
			   $('#workNumber').textbox('setValue', $(this).val());
			   query();
		    }
		});
	
	$('#userName').textbox('textbox').keydown(function (e) {
	   if (e.keyCode == 13) {
		   $('#userName').textbox('setValue', $(this).val());
		   query();
	    }
	});
	$('#realName').textbox('textbox').keydown(function (e) {
		   if (e.keyCode == 13) {
			   $('#realName').textbox('setValue', $(this).val());
			   query();
		    }
		});
	$('#operatorType').textbox('textbox').keydown(function (e) {
		if (e.keyCode == 13) {
			query();
		}
	});
});

//刷新
function reload(){
	$("#workNumber").textbox('setValue','');
	$("#userName").textbox('setValue','');
 	$("#realName").textbox('setValue','');
 	$("#operatorModules").combotree('setValue','');
 	$("#operatorType").combobox('setValue','');
	query();
}

//查询
function query(){
	$("#dataGridTable").datagrid('reload',{
		'sysOperatorLog.workNumber' : $("#workNumber").val(),
	 	'sysOperatorLog.userName' : $("#userName").val(),
	 	'sysOperatorLog.operatorType' : $("#operatorType").combobox('getValue'),
	 	'sysOperatorLog.operatorModules' : $("#operatorModules").combotree('getText'),
	 	'sysOperatorLog.realName' :$("#realName").val()
	}); 
}

//初始化详细信息模态框
function operatorLogFrame(){
	$("#operatorLogFrame").dialog({
		title:'日志详细信息',
		height:280,
		modal:true,
		collapsible:true,
		resizable:false
	});
}

//关闭详细信息模态框
function closeOperatorLogFrame(){
	$('#operatorLogFrame').dialog('close');
}

//双击行打开详细信息表
function operatorLogFrameMod(){
	if($('#dataGridTable').datagrid('getSelected')){
		var operatorId = $('#dataGridTable').datagrid('getSelections')[0].operatorId;
		$.ajax({
			async : false,
			cache:false,
			type: 'POST',
			dataType : "json",
			url: 'sys/queryOperatorLog.action',//请求的action路径
			data : {
				"sysOperatorLog.operatorId":operatorId
			},
			success:function(data,action,opt){
				$("#details_workNumber").text(data.rows[0].workNumber);
				$("#details_userName").text(data.rows[0].userName);
				$("#details_realName").text(data.rows[0].realName);
				$("#details_operatorIp").text(data.rows[0].operatorIp);
				$("#details_operatorContent").text(data.rows[0].operatorContent);
				$("#details_operatorRemark").text(data.rows[0].operatorRemark);
				$("#details_createTime").text(data.rows[0].createTime);
			}
		});
		$("#operatorLogFrame").dialog('open');
	} else {
		noSelectData();
	}
}

//类型
function operatorTypeFormater(value,row){
	var operatorType = row.operatorType;
	if(operatorType=='1'){
		operatorType='增加';
	}else if(operatorType=='2'){
		operatorType='删除';
	}else if(operatorType=='3'){
		operatorType='修改';
	}else if(operatorType=='4'){
		operatorType='查询';
	}
	return operatorType;
};